<?php
/**
 * Range Rule
 * Validate that a value is between min and max
 * 
 * @package     Q-Validate
 * @subpackage  Rules
 * @author      Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright   (c) 2010 Luke Visinoni <luke.visinoni@gmail.com>
 * @version     $Id: Range.php 37 2010-12-23 02:38:44Z luke.visinoni $
 */
class Q_Rule_Range extends Q_Rule_Abstract {

    /**
     * The parameters that were passed to this rule
     */
    protected $_params = array(
        'min' => null,
        'max'=> null,
    );
	
    /**
     * Validate range
     */
    public function isValid($value) {
    
		// Only maximum defined
		if ($this->getParam('min') == NULL) {
			return ($value <= $this->getParam('max'));
		}
		// Only minimum defined
		if ($this->getParam('max') == NULL) {
			return ($value >= $this->getParam('min'));
		}
		// Range defined
		return (($this->getParam('min') <= $value) && ($value <= $this->getParam('max')));
    
    }

}
